﻿<UserControl 
  x:Class="iTFF.WPF.View.GlobalHotKeysView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:ui="clr-namespace:iTFF.WPF.UI"
  xmlns:l="clr-namespace:iTFF.WPF.Resources.Languages">

  <UserControl.Resources>
    <ui:NotBooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter" />
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <ui:NotBooleanConverter x:Key="NotBooleanConverter" />
  </UserControl.Resources>

  <Border Style="{StaticResource tabItemBorderStyle}">
    <ScrollViewer VerticalScrollBarVisibility="Auto">
      <Grid HorizontalAlignment="Left">
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ListView Margin="5" BorderThickness="0"
        ItemsSource="{Binding HotKeys}">
          <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
              <Style.Triggers>
                <DataTrigger Binding="{Binding HasSeparatorBefore}" Value="True">
                  <Setter Property="Margin" Value="0,15,0,0" />
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </ListView.ItemContainerStyle>

          <ListView.View>
            <GridView>
              <GridView.ColumnHeaderContainerStyle>
                <Style TargetType="{x:Type GridViewColumnHeader}">
                  <Setter Property="Visibility" Value="Collapsed" />
                </Style>
              </GridView.ColumnHeaderContainerStyle>

              <GridView.Columns>
                <GridViewColumn>
                  <GridViewColumn.CellTemplate>
                    <DataTemplate>
                      <TextBlock Text="{Binding DisplayName}" TextWrapping="WrapWithOverflow" MaxWidth="270" />
                    </DataTemplate>
                  </GridViewColumn.CellTemplate>
                </GridViewColumn>

                <GridViewColumn>
                  <GridViewColumn.CellTemplate>
                    <DataTemplate>
                      <TextBox x:Name="tb" Text="{Binding KeysCombination, Mode=OneWay}" Width="230" 
                             IsEnabled="{Binding CanEdit}"
                             ui:ControlBehaviours.PreviewKeyDownCommand="{Binding PreviewKeyDownCommand}" />
                      <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding IsInvalid}" Value="True">
                          <Setter Property="BorderThickness" TargetName="tb" Value="2" />
                          <Setter Property="BorderBrush" TargetName="tb" Value="Red" />
                        </DataTrigger>
                      </DataTemplate.Triggers>
                    </DataTemplate>
                  </GridViewColumn.CellTemplate>
                </GridViewColumn>

                <GridViewColumn>
                  <GridViewColumn.CellTemplate>
                    <DataTemplate>
                      <CheckBox IsChecked="{Binding IsWinKeyPressed}" 
                      IsEnabled="{Binding CanEdit}"
                      Content="Win" />
                    </DataTemplate>
                  </GridViewColumn.CellTemplate>
                </GridViewColumn>

              </GridView.Columns>
            </GridView>
          </ListView.View>
        </ListView>

        <Grid Grid.Row="1">
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
          </Grid.ColumnDefinitions>

          <TextBlock Text="{x:Static l:Strings.GlobalHotKeysViewHitEscape}" FontStyle="Italic" FontWeight="Bold"
                   Margin="10,0,0,0" VerticalAlignment="Center" />

          <StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,10,0">

            <ToggleButton IsChecked="{Binding IsEditingHotKeys, Mode=TwoWay}" 
                      Visibility="{Binding IsEditingHotKeys, Converter={StaticResource NotBooleanToVisibilityConverter}}">
              <StackPanel Orientation="Horizontal" Margin="2">
                <Image Source="../Resources/Images/page_edit.png" Width="16" Height="16" Margin="2" />
                <TextBlock Text="{x:Static l:Strings.GlobalHotKeysViewEditHotKeys}" Margin="2" />
              </StackPanel>
            </ToggleButton>

            <Button Visibility="{Binding IsEditingHotKeys, Converter={StaticResource BooleanToVisibilityConverter}}"
                Command="{Binding ApplyCommand}" Margin="4,0">
              <StackPanel Orientation="Horizontal" Margin="2">
                <Image Source="../Resources/Images/tick.png" Width="16" Height="16" Margin="2" />
                <TextBlock Text="{x:Static l:Strings.Apply}" />
              </StackPanel>
            </Button>

            <Button Visibility="{Binding IsEditingHotKeys, Converter={StaticResource BooleanToVisibilityConverter}}"
                Command="{Binding CancelCommand}" Margin="4,0">
              <StackPanel Orientation="Horizontal" Margin="2">
                <Image Source="../Resources/Images/cross.png" Width="16" Height="16" Margin="2" />
                <TextBlock Text="{x:Static l:Strings.Cancel}" />
              </StackPanel>
            </Button>

          </StackPanel>

        </Grid>

      </Grid>
    </ScrollViewer>



  </Border>

</UserControl>
